//
//  MZWebViewDemoViewController.m
//  MZToolkitDemo
//
//  Created by 沈家林 on 2017/5/12.
//  Copyright © 2017年 Chris Yang. All rights reserved.
//

#import "MZWebViewDemoViewController.h"
#import <WebKit/WebKit.h>

@interface MZWebViewDemoViewController ()<UIWebViewDelegate,WKUIDelegate,WKNavigationDelegate>

@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, strong) WKWebView *wkWebView;

@end

@implementation MZWebViewDemoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _webView = [[UIWebView alloc] init];
    [_webView setDelegate:self];
    [self.view addSubview:_webView];
    [_webView setFrame:self.view.bounds];
    
    
    NSURLRequest *tmpReq = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://baidu.com"]];
    [_webView loadRequest:tmpReq];
    
    _wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    [_wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]];
    _wkWebView.UIDelegate=self;
    _wkWebView.navigationDelegate=self;
    [self.view addSubview:_wkWebView];
}

#pragma mark - UIWebViewDelegate (For simple test)

- (BOOL)webView:(UIWebView*)webView
 shouldStartLoadWithRequest:(NSURLRequest*)request
             navigationType:(UIWebViewNavigationType)navigationType {
    
    NSLog(@"------:%@", [request valueForHTTPHeaderField:@"User-Agent"]);
    return YES;
}

#pragma mark - WKWebViewDelegate (For simple test)
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    [webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
        NSLog(@"userAgent :%@", result);
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
